package com.ch.gulimall.product.entity;

import com.baomidou.mybatisplus.annotation.TableId;
import com.baomidou.mybatisplus.annotation.TableName;

import java.io.Serializable;

import com.ch.common.valid.AddGroup;
import com.ch.common.valid.ListValue;
import com.ch.common.valid.UpdateGroup;
import com.ch.common.valid.UpdateStatusGroup;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.NonNull;
import org.hibernate.validator.constraints.URL;

import javax.validation.constraints.*;

/**
 * 品牌
 * 分组校验:
 * 1.写两个接口
 * groups代表说如果你的controller的注解给加上了对应的接口的约束 就会触发我们的字段自定义校验规则
 * @author chenHao
 * @email 1429542285@qq.com
 * @date 2022-02-06 12:47:04
 */
@NoArgsConstructor
@Data
@TableName("pms_brand")
public class BrandEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	/**
	 * 品牌id
	 */
	@Null(message = "新增不能指定id",groups = {AddGroup.class})
	@NotNull(message = "修改必须指定id",groups = {UpdateGroup.class})
	@TableId
	private Long brandId;
	/**
	 * 品牌名
	 */
	@NotBlank(groups = {AddGroup.class})
	@NotBlank(message = "品牌名不能为空",groups = {AddGroup.class,UpdateGroup.class})
	private String name;
	/**
	 * 品牌logo地址
	 */
	@NotEmpty(groups = {AddGroup.class})
	@URL(message = "logo的URL必须是合法的",groups = {AddGroup.class,UpdateGroup.class})
	private String logo;
	/**
	 * 介绍
	 */
	@NotEmpty(groups = {AddGroup.class,UpdateGroup.class})
	private String descript;
	/**
	 * 显示状态[0-不显示；1-显示]
	 */
	@NotNull(groups = {AddGroup.class,UpdateStatusGroup.class})
	@ListValue(vals = {0,1},groups = {AddGroup.class,UpdateStatusGroup.class})
	private Integer showStatus;
	/**
	 * 检索首字母
	 */
	@NotEmpty(groups = {AddGroup.class,UpdateGroup.class})
	@Pattern(regexp = "^[a-zA-Z]$",message = "首字母必须是26个字母",groups = {AddGroup.class,UpdateGroup.class})
	private String firstLetter;
	/**
	 * 排序
	 */
	@NotNull(groups = {AddGroup.class,UpdateGroup.class})
	@Min(value = 0,message = "排序必须大于0",groups = {AddGroup.class,UpdateGroup.class})
	private Integer sort;

	public BrandEntity(Long brandId, String name, String logo, String descript, Integer showStatus, String firstLetter, Integer sort) {
		this.brandId = brandId;
		this.name = name;
		this.logo = logo;
		this.descript = descript;
		this.showStatus = showStatus;
		this.firstLetter = firstLetter;
		this.sort = sort;
	}
}
